home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #46 (Jul 89) / Basic Source / GETINDSTRING.S next >
Text File  |  1989-05-19  |  1KB  |  39 lines

  1. 'V
  2. 'S
  3. 'GETINDSTRING$ function By Charles Stricklin
  4. 'Modified by Dave Kelly for MacTutor, May, 1989
  5.  
  6. 'This function is identical to the procedure GetIndString
  7. 'which is not in ROM and not supported by ZBasic.  It reads
  8. 'a string from a string list and returns a copy of it in the
  9. 'variable the String$.  If the string list doesn't exist of the
  10. 'index is out of range an empty string is returned.
  11.  
  12. ' stringListID is the resource ID of the string list; it's resource type is 'STR#'.
  13. ' stringIndex is the index of the desired string within the list.
  14.  
  15. LONG FN GETINDSTRING$(StringListID, StringIndex)
  16.     TheString$=""
  17.     Offset=0
  18.     FALSE=0
  19.     MyHandle&=FN GETRESOURCE(CVI("STR#"),StringListID)
  20.     LONG IF FN RESERROR=FALSE
  21.         MyPointer&=USR 3(MyHandle&)
  22.         NumberOfStrings=PEEK WORD(MyPointer&)
  23.         LONG IF (StringIndex>0) AND (StringIndex <= NumberOfStrings)
  24.             LONG IF StringIndex>1
  25.                 FOR ThisString=1 TO StringIndex-1
  26.                     LengthOfThisString=PEEK(MyPointer&+2+Offset)
  27.                     Offset=Offset+LengthOfThisString+1
  28.                 NEXT
  29.             END IF
  30.             LengthOfDesiredString=PEEK(MyPointer&+2+Offset)
  31.             FOR Character=1 TO LengthOfDesiredString
  32.                 TheString$=TheString$+CHR$(PEEK(MyPointer&+2+Offset+Character))
  33.             NEXT
  34.         END IF
  35.     MyHandle&=USR 7(MyPointer&)
  36.     CALL DETACHRESOURCE(MyHandle&)
  37.     END IF
  38. END FN= TheString$
  39.